/**
 * 用于用户登录一些接口
 */
import request from '@/proxy/request'
import {getToken} from "@/utils/token.js";


/**
 * 登录
 * @returns {*}
 */
export function login(data) {
    let dataUser = data.username
    let dataPass = data.password
    let dataCode = data.code
    return request({
        url: '/auth/oauth/token',
        method: 'POST',
        params: {
            username: dataUser,
            password: dataPass,
            grant_type: 'password',
            code: dataCode,
            scope: 'server'
        },
        auth: {
            username: 'pig',
            password: 'pig'
        }
    })
}

/**
 * 验证码
 */
export function codeGen() {
    return request({
        url: '/admin/sys-user/create-code',
        method: 'get'
    })
}

/**
 * 登出
 * @returns {*}
 */
export function logOut() {
    return request({
        url: '/auth/token/logout',
        method: 'delete',
        headers: {
            'Authorization': getToken()
        },
    })
}


/**
 * 登录用户信息
 * @param userName
 * @returns {*}
 */
export function getLoginUserInfo() {
    return request({
        url: `/admin/sys-user/info/security`,
        method: 'GET'
    })
}
